package io.renren.dao;

import io.renren.common.dao.BaseDao;
import io.renren.dto.StockOrderDTO;
import io.renren.entity.StockOrderEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 食材采购表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Mapper
public interface StockOrderDao extends BaseDao<StockOrderEntity> {
    @Select(" SELECT * from canteens_stock_order am ,canteens_stock_ordermx mx where am.`status`>1 and mx.supplier_id = "+
            "'${id}'  GROUP BY am.stock_order_id ORDER BY am.create_date desc"
    )
    List<StockOrderDTO> selectSupplierOed(Long id);
    @Select("DELETE from  canteens_stock_order   where stock_order_id = " +
            "'${canteens_stock_order}'")
    void deleteOrder(Long id);

    @Select("SELECT  COUNT(*) as pending   from  canteens_stock_order where  `status` = '${status}' ${chedId} ${clerkId} ${canteen_Id} ")
    StockOrderDTO getTotal(String chedId, String clerkId,String canteen_Id ,int status);

    @Select(" SELECT * FROM canteens_stock_order where `status`>=4 and  DATE_FORMAT('${bgeinDate}','%Y-%m-%d') <= DATE_FORMAT(create_date,'%Y-%m-%d') " +
            "and DATE_FORMAT('${endDate}','%Y-%m-%d') >= DATE_FORMAT(create_date,'%Y-%m-%d')")
    List<StockOrderDTO> getOrderNum(String bgeinDate,String endDate);
    @Select("SELECT B.* FROM canteens_stock_ordermx A ,canteens_stock_order B where B.`status`>=4 " +
            "and  DATE_FORMAT('${bgeinDate}','%Y-%m-%d') <= DATE_FORMAT(B.create_date,'%Y-%m-%d') " +
            " and DATE_FORMAT('${endDate}','%Y-%m-%d') >= DATE_FORMAT(B.create_date,'%Y-%m-%d') " +
            " and A.stock_order_id = B.stock_order_id " +
            " and A.supplier_id = '${supplierId}' GROUP BY B.stock_order_id")
    List<StockOrderDTO> getOrder2(String bgeinDate, String endDate, long supplierId);
}